package io.github.ilkgunel.dao;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import io.github.ilkgunel.database.AccessMongoDB;
import io.github.ilkgunel.pojo.Course;
import io.github.ilkgunel.pojo.Teacher;
import org.bson.Document;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class coursefind {
    public List<Course> find()
    {
        List<Course> list = new ArrayList<>();
        //FindIterable<Document> result = getMongoDatabase().getCollection("Records").find(new Document("name","Can"));
        AccessMongoDB accessMongoDB = new AccessMongoDB();



        FindIterable<Document> result = accessMongoDB.getCollection("course").find();


        MongoCursor<Document> cursor = result.iterator();
        while (cursor.hasNext()) {

            Document document = cursor.next();


            String temp;
            Course s=new Course();
            s.set_id(document.get("_id").toString());


            s.setCid(document.get("cid").toString());
            s.setName(document.get("name").toString());
            s.setFcid( document.get("fcid").toString());


            temp= new BigDecimal((document.get("credit")).toString()).toPlainString();
            s.setCredit(Double.parseDouble( temp));







           /* Address address1 = new Address();
            address1.setStreet(( address.get("street"));
            address1.setBorough((String) address.getString("borough"));
            address1.setCity((String) address.getString("city"));

            Record record = new Record();
            record.setId(document.get("_id").toString());
            record.setName((String) document.get("name"));
            record.setSurname((String) document.get("surname"));
            record.setAddress(address1);
*/
            list.add(s);
        }
        return list;
    }
}
